package com;

import java.sql.*;
import java.util.*;

public class GetNewsList {
    DBcon db = new DBcon();
    ResultSet rs;
    String sql = "";
    ArrayList<News> newsList = new ArrayList<News>();

    public ArrayList<News> getList() {
        sql = "select * from news";
        rs = db.Query(sql);
        try {
            while (rs.next()) {
                News news = new News();
                news.setId(rs.getInt("id"));
                news.setTitle(rs.getString("title"));
                news.setContent(rs.getString("content"));
                news.setImage(rs.getString("image"));
                news.setAuthor(rs.getString("author"));
                news.setType(rs.getString("type"));
                news.setKeywords(rs.getString("keywords"));
                news.setPubtime(rs.getString("pubtime"));
                newsList.add(news);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return newsList;
    }
}
